package org.dromara.data.dnnyun.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.curd.dnnyun.domain.vo.DnnyunStoreAchievementVo;
import org.dromara.data.dnnyun.service.IDnnyunDataService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.curd.dnnyun.domain.bo.DnnyunStoreAchievementBo;
import org.dromara.curd.dnnyun.service.IDnnyunStoreAchievementService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 店面业绩统计
 *
 * @author wdm
 * @date 2024-03-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/data/dnnyun/storeAchievement")
public class DnnyunStoreAchievementController extends BaseController {

    private final IDnnyunStoreAchievementService dnnyunStoreChievementService;
    private final IDnnyunDataService dnnyunDataService;

    /**
     * 查询店面业绩统计列表
     */
    @SaCheckPermission("data:dnnyun:storeAchievement:list")
    @GetMapping("/list")
    public TableDataInfo<DnnyunStoreAchievementVo> list(DnnyunStoreAchievementBo bo, PageQuery pageQuery) {
        return dnnyunStoreChievementService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出店面业绩统计列表
     */
    @SaCheckPermission("data:dnnyun:storeAchievement:export")
    @Log(title = "店面业绩统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DnnyunStoreAchievementBo bo, HttpServletResponse response) {
        List<DnnyunStoreAchievementVo> list = dnnyunStoreChievementService.queryList(bo);
        ExcelUtil.exportExcel(list, "店面业绩统计", DnnyunStoreAchievementVo.class, response);
    }

    /**
     * 获取店面业绩统计详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("data:dnnyun:storeAchievement:query")
    @GetMapping("/{id}")
    public R<DnnyunStoreAchievementVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(dnnyunStoreChievementService.queryById(id));
    }

    /**
     * 新增店面业绩统计
     */
    @SaCheckPermission("data:dnnyun:storeAchievement:add")
    @Log(title = "店面业绩统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DnnyunStoreAchievementBo bo) {
        return toAjax(dnnyunStoreChievementService.insertByBo(bo));
    }

    /**
     * 修改店面业绩统计
     */
    @SaCheckPermission("data:dnnyun:storeAchievement:edit")
    @Log(title = "店面业绩统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DnnyunStoreAchievementBo bo) {
        return toAjax(dnnyunStoreChievementService.updateByBo(bo));
    }

    /**
     * 删除店面业绩统计
     *
     * @param ids 主键串
     */
    @SaCheckPermission("data:dnnyun:storeAchievement:remove")
    @Log(title = "店面业绩统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(dnnyunStoreChievementService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 查询店面业绩统计列表
     */
    @SaCheckPermission("data:dnnyun:storeAchievement:sync")
    @GetMapping("/sync")
    public R sync(DnnyunStoreAchievementBo bo) {
        dnnyunDataService.syncStoreAchievementList(bo);
        return R.ok();
    }
}
